require(['loading'], function(loading) {
    var pageNo = 1;
    var pageSize = 10;
	
    //应用实例化
    var searchBody = new Vue({
        el: '#searchBody',
        data: {
            searchList: [],
            apiUrl: wxUrl + '/v3.2/farm/suggest',
            keyword:'',
            item: {
                params:{
                    token: token,
                    keyword: '',
                    type: 1,
                    pageNo : pageNo,
                    pageSize : pageSize
                }
            }
        },
        ready: function() {
            this.init();
        },
        methods:{
            init: function(){
//              $("#search")[0].focus();
				 document.querySelector('#search').addEventListener('click', function(event){
				    (this||delegate.obj).focus();
				},false);
            },
            clearMsg: function(e){
                $(e.target).hide();
                this.keyword = '';
                $('.content').val('');
            },
            searchOnkeyup: function(){
                $('.clear').show();
                this.item.params.keyword = this.keyword;
                if(this.keyword.length < 1){
                	return false;
                }
                this.$http.get(this.apiUrl, this.item)
                	.then(function(response) {
                        var result = JSON.parse(response.body);
                        var newD = document.getElementById("newD");
                        if(!newD){
                        	if(result.data.result.length > 0){
	                        	var slist = result.data.result;
                        		this.$set('searchList', slist);
		                        $('.list').show();
	                        } else {
	                        	promptBox('无匹配的农庄!');
	                        	$(".promptBox").css("bottom","70%");
	                        }
                        }
                    },
                    function(response) {
                        //errorCallback
                    });
            },
            jumpDetail: function(id){
                window.location.href = "../yellowPage/yellowPage_detail.html?id=" + id;
            }
        }
    });
});

// 为可控制返回指定页面所有添加pushState
history.pushState({}, document.title, null);
pushVHistory();
window.addEventListener("popstate", function() {
    // 跳转到订单列表页面
	goBackVHistory();
});